package 寒假作业.LeetCode;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Stack;

public class Num1441 {
    public List<String> buildArray(int[] target, int n) {
        List<String> list = new ArrayList<>();
        Stack<Integer> stack = new Stack<>();
        for (int i = 1 , index = 0; i <= n && index < target.length; i++) {
            stack.add(i);
            list.add("Push");
            if (target[index] != stack.peek()){
                stack.pop();
                list.add("Pop");
            }else {//当栈的元素和数组对应上才++
                index ++;
            }
        }
        return list;
    }
}
